local skynet = require "skynet"

local LogFile = {}

local TEST_LEVEL			=1--,			//测试 日志
local DEBUG_LEVEL			=2--,			//调试日志
local RELEASE_LEVEL			=3--,			//发布之后的日志
local ERROR_LEVEL			=4--,			//错误日志

local LOGGER_NAME = ".logger"

LogFile.level_ = nil

local function log(nowlevel,... )
	if not LogFile.level_ then
		LogFile.level_ = skynet.call(LOGGER_NAME,"lua","sync_log_level")
	end

	if LogFile.level_ <= nowlevel then
		local len = select("#",...)
		local temp = {...}
		for i=1,len do
			temp[i] = tostring(temp[i])
		end
		skynet.send(LOGGER_NAME,"lua","log",nowlevel,table.unpack(temp))
	end
end

function LogFile.Debug( ... )
	log(DEBUG_LEVEL,...)
end


function LogFile.Test( ... )
	log(TEST_LEVEL,...)
end


function LogFile.Err( ... )
	log(ERROR_LEVEL,...)	
end

function LogFile.Rel( ... )
	log(RELEASE_LEVEL,...)	
end

function LogFile.cmd(cmd,level,...)
	if cmd == "loggerlevelupdate" then
		LogFile.level_ = skynet.call(LOGGER_NAME,"lua","sync_log_level")
	end
end

return LogFile